package com.cacho.s2b.lesson.learn;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;

import java.util.HashMap;
import java.util.Map;

import static io.restassured.RestAssured.given;

/**
 * @Description  rest-assured 是由Java实现的REST API测试框架
 * @Author LingWei
 * @date 2023/12/31
 **/
public class LearnRestassured {
    public static void main(String[] args) {
        RestAssured.reset(); // 重置设置，上面的设置就无效
        RestAssured.useRelaxedHTTPSValidation();  // 忽略 https SSL校验
        //given().contentType(ContentType.JSON); // 请求头、请求参数、请求体、cookie
        String url = "https://api.pearktrue.cn/api/lsjt/?type=json";
        Map<String,String > headerMap = new HashMap<>();
        Response req = given().contentType(ContentType.JSON).headers(headerMap).when().get(url); // 发起请求
        System.out.println("响应的状态码："+req.statusCode());
        //System.out.println("获取响应结果1："+req.asString());
        //System.out.println("获取响应结果2："+req.thenReturn().asString());
        //System.out.println("获取响应结果3："+req.asPrettyString());
        System.out.println("获取响应结果4："+req.getBody().asPrettyString());
    }
}
